home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / sot.zip / SOTL.C < prev    next >
Text File  |  1988-08-23  |  6KB  |  211 lines

  1. /********** The Son of Tetris Project ************/
  2.  
  3. /************  get LEVEL value etc. ***********/
  4.  
  5. #include <conio.h>
  6. #include <ctype.h>
  7. #include <setjmp.h>
  8. #include <stdio.h>
  9.  
  10. #include "sot.h"
  11.  
  12. #define LEVEL_COL 19
  13. #define LEVEL_ROW 14
  14. #define LEVEL_WIDTH 48
  15. #define LEVEL_DEPTH 5
  16.  
  17. #define AG_COL 19
  18. #define AG_ROW 18
  19. #define AG_WIDTH 46
  20. #define AG_DEPTH 5
  21.  
  22. #define CH_COL 19
  23. #define CH_ROW 7
  24. #define CH_WIDTH 46
  25. #define CH_DEPTH 10
  26.  
  27. #define PG_COL 19
  28. #define PG_ROW 10
  29. #define PG_WIDTH 46
  30. #define PG_DEPTH 8
  31.  
  32. #define NN_COL 19
  33. #define NN_ROW 10
  34. #define NN_WIDTH 46
  35. #define NN_DEPTH 8
  36.  
  37. extern jmp_buf    end_game;
  38.  
  39. static void set_window(int left,int top,int right,int bot,void *store)
  40. {
  41.   textattr((BLACK << 4) + WHITE);
  42.   gettext(left, top, right, bot, store);
  43.   window(left,top,right,bot); gotoxy(1,1);
  44.   cursor_on();
  45. }
  46.  
  47. static void lose_window(int left,int top,int right,int bot,void *store)
  48. {
  49.   cursor_off();
  50.   textattr((BLACK << 4) + LIGHTGRAY);
  51.   window(1,1,80,25);
  52.   puttext(left, top, right, bot, store);
  53. }
  54.  
  55.  
  56.  
  57. unsigned get_level(void)
  58. {
  59.   int store[LEVEL_WIDTH * LEVEL_DEPTH * 2];
  60.   unsigned result = 5;
  61.   int char_in;
  62.  
  63.   set_window(LEVEL_COL,LEVEL_ROW,LEVEL_COL + LEVEL_WIDTH,LEVEL_ROW + LEVEL_DEPTH, store);
  64.   cputs("┌──────────────────────────────────────────┐\n");
  65.   cputs("│                                          │\n");
  66.   cputs("│ Enter your starting level (0-9) [5] >    │\n");
  67.   cputs("│                                          │\n");
  68.   cputs("└──────────────────────────────────────────┘\n");
  69.  
  70.   gotoxy(41,3);
  71.   char_in = getch();
  72.   if (char_in == ESC)
  73.     longjmp(end_game,1);
  74.   if(isdigit(char_in))
  75.     result = char_in - '0';
  76.   putch(result + '0');
  77.  
  78.   lose_window(LEVEL_COL,LEVEL_ROW,LEVEL_COL + LEVEL_WIDTH,LEVEL_ROW + LEVEL_DEPTH, store);
  79.   return(result);
  80. } /* get_level */
  81.  
  82.  
  83.  
  84. void  get_new_name(char *name)
  85. {
  86.   int store[NN_WIDTH * NN_DEPTH * 2], count;
  87.  
  88.   set_window(NN_COL,NN_ROW,NN_COL + NN_WIDTH,NN_ROW + NN_DEPTH, store);
  89.   cputs("┌──────────────────────────────────────────┐\n");
  90.   cputs("│ Brill score cobber!                      │\n");
  91.   cputs("│ Enter your name >                        │\n");
  92.   cputs("└──────────────────────────────────────────┘\n");
  93.  
  94.   gotoxy(21,3);
  95.   for (count = 0;
  96.        count < 19;
  97.        name++, count++)
  98.   {
  99.     *name = getche();
  100.     if (*name == '\b')
  101.     {
  102.       count -= 2;
  103.       if (count < -1)
  104.       {
  105.     *name = 0;
  106.         lose_window(NN_COL,NN_ROW,NN_COL + NN_WIDTH,NN_ROW + NN_DEPTH, store);
  107.     return;
  108.       }
  109.       putch(' '); putch('\b');
  110.       name-=2;
  111.     }
  112.     if (*name == '\r')
  113.       break;
  114.  
  115.     if (*name == ESC)
  116.       longjmp(end_game,1);
  117.   }
  118.   *name = 0; /* Terminate string */
  119.  
  120.   lose_window(NN_COL,NN_ROW,NN_COL + NN_WIDTH,NN_ROW + NN_DEPTH, store);
  121. }  /* get_new_name */
  122.  
  123.  
  124.  
  125. unsigned  get_another_go(long new_score) /* Dialogue between games */
  126. {
  127.   int store[AG_WIDTH * AG_DEPTH * 2], ch_store[CH_WIDTH * CH_DEPTH * 2];
  128.   auto unsigned result = TRUE;
  129.   char name[20];
  130.   long score;
  131.   int rank;
  132.  
  133.   champ_val(name, &score, TABLE_LEN);  /* get current bottom of table */
  134.  
  135.   if (score < new_score)
  136.   {
  137.     get_new_name(name);
  138.     update_score_table(name, new_score);
  139.   }
  140.  
  141.   set_window(CH_COL,CH_ROW,CH_COL + CH_WIDTH,CH_ROW + CH_DEPTH, ch_store);
  142.   cputs("┌────────────────────────────────────────┐\n");
  143.   cputs("│  SOT Champions                         │\n");
  144.   cputs("│                                        │\n");
  145.   cputs("│  1.                                    │\n");
  146.   cputs("│  2.                                    │\n");
  147.   cputs("│  3.                                    │\n");
  148.   cputs("│  4.                                    │\n");
  149.   cputs("│  5.                                    │\n");
  150.   cputs("│                                        │\n");
  151.   cputs("└────────────────────────────────────────┘\n");
  152.  
  153.   for (rank = 1; rank <= TABLE_LEN; rank++)
  154.   {
  155.     champ_val(name, &score, rank);
  156.     gotoxy(7,rank+3);
  157.     if (score)
  158.       cprintf("%-20s  %8ld",name,score);
  159.     else
  160.       break;
  161.   } /* for */
  162.  
  163.  
  164.  
  165.   set_window(AG_COL,AG_ROW,AG_COL + AG_WIDTH,AG_ROW + AG_DEPTH, store);
  166.   cputs("┌────────────────────────────────────────┐\n");
  167.   cputs("│                                        │\n");
  168.   cputs("│ Do you want another go? (Y/N) [Y] >    │\n");
  169.   cputs("│                                        │\n");
  170.   cputs("└────────────────────────────────────────┘\n");
  171.  
  172.   gotoxy(39,3);
  173.   if (toupper(getch()) == 'N')
  174.   {
  175.     result = FALSE;
  176.     putch('N');
  177.   }
  178.   else
  179.     putch('Y');
  180.  
  181.   lose_window(AG_COL,AG_ROW,AG_COL + AG_WIDTH,AG_ROW + AG_DEPTH, store);
  182.   lose_window(CH_COL,CH_ROW,CH_COL + CH_WIDTH,CH_ROW + CH_DEPTH, ch_store);
  183.   return(result);
  184. } /* get_another_go */
  185.  
  186.  
  187. unsigned pause_game(void)
  188. {
  189.   int store[PG_WIDTH * PG_DEPTH * 2];
  190.   unsigned result = FALSE;
  191.  
  192.   set_window(PG_COL,PG_ROW,PG_COL + PG_WIDTH,PG_ROW + PG_DEPTH, store);
  193.   cputs("┌──────────────────────────────────────────┐\n");
  194.   cputs("│                                          │\n");
  195.   cputs("│ PAUSED...                                │\n");
  196.   cputs("│                                          │\n");
  197.   cputs("│ Press a key when you are ready to go on, │\n");
  198.   cputs("│ or use ESC to quit >                     │\n");
  199.   cputs("│                                          │\n");
  200.   cputs("└──────────────────────────────────────────┘\n");
  201.  
  202.   gotoxy(24,6);
  203.   if (getch() == ESC)
  204.     result = TRUE;
  205.  
  206.   lose_window(PG_COL,PG_ROW,PG_COL + PG_WIDTH,PG_ROW + PG_DEPTH, store);
  207.   return(result);
  208.  
  209. } /* pause_game */
  210.  
  211.